<template>
  <div>
    <!-- 详情 -->
    <div class="layout-container-detail">
      <div class="detail-page-name"> <span @click="goProjectMs">项目管理</span> / 项目详情</div>
      <div>
        <el-row class="el-row-item" v-for="(projectDetailInfo, projectIndex) in projectDataAll" :key="projectIndex" >
          <el-col :span="24" class="detail-page-title" v-if="projectDetailInfo.title">
            <div class="detail-page-title-top">
              <div class="detail-title">{{ projectDetailInfo.title }}</div>
              <div class="detail-sort">排序值：{{ projectDetailInfo.sort }}</div>
            </div>
            <!-- 子管理员没有权限 -->
            <div v-if="adminInfo.admin_type === 0">
              <el-button v-if="projectDetailInfo.status !== 1" type="primary"
                @click="handleOptStatus(projectDetailInfo.status)">上线</el-button>
              <el-button v-else type="primary" @click="handleOptStatus(projectDetailInfo.status)">下线</el-button>
            </div>
          </el-col>
          <template v-if="projectDetailInfo.onlyBtn || projectDetailInfo.project_id">
           <el-col :span="24" :offset="0" v-if="projectIndex>0">
                项目{{projectIndex == 1?'一':'二'}}审：
                <template v-if="projectDetailInfo.onlyBtn">
                  <el-button
                    v-if="adminInfo.admin_type < 2 || (adminInfo.admin_type === 2 && adminInfo.action_permissions.includes('2'))"
                    type="primary" @click="handleBatchImport(projectIndex == 1?6:8)">
                    上传配置表开启{{projectIndex == 1?'一':'二'}}审
                  </el-button>
                </template>
                <template v-else>
                   <el-button
                        v-if="adminInfo.admin_type < 2 || (adminInfo.admin_type === 2 && adminInfo.action_permissions.includes('2'))"
                        type="primary" @click="handleBatchImport(projectIndex == 1?7:9)">
                        上传表格修改{{projectIndex == 1?'一':'二'}}审配置
                      </el-button>
                </template>
                 
            </el-col>
          </template>
          <template v-if="projectDetailInfo.project_id">
              <el-col :span="6">项目ID：{{ projectDetailInfo.project_id }}</el-col>
              <el-col :span="6">
                  无需项目权限即可看见项目
                <el-switch 
                  v-model="projectDetailInfo.visibility_status" 
                   :before-change="(()=>{return changeProjectInfoStatus(projectDetailInfo,projectIndex,'visibility')})"
                  />
                 
                  
              </el-col>
              <el-col :span="6">封面图：
                <!-- {{uploadList.url}} -->
                <el-image v-if="projectDetailInfo.cover" style="
                    width: 80px;
                    height: 50px;
                    cursor: pointer;
                    margin-right: 10px;
                  " :src="projectDetailInfo.cover" :preview-src-list="[projectDetailInfo.cover]" />
                <!-- v-if="adminInfo.admin_type < 2 || (adminInfo.admin_type === 2 && adminInfo.action_permissions.includes('2'))" -->
                <el-upload ref="upload" :accept="uploadObjImg.accept" :show-file-list="false" :auto-upload="true"
                  :http-request="((fileInfo)=>{ return uploadFileFun(fileInfo,projectDetailInfo)})">
                  <template #default>
                    <el-button type="text">上传封面图</el-button>
                  </template>
                </el-upload>
                <el-button style="margin-left:20px" type="text" @click="delImg(projectDetailInfo,projectIndex)">删除</el-button>
              </el-col>
              <el-col :span="6">
                首页轮播封面图：
                <!-- {{uploadBannerList.url}} -->
                <el-image v-if="projectDetailInfo.banner" style="
                    width: 80px;
                    height: 30px;
                    cursor: pointer;
                    margin-right: 10px;
                  " :src="projectDetailInfo.banner" :preview-src-list="[projectDetailInfo.banner]" />
                <!-- v-if="adminInfo.admin_type < 2 || (adminInfo.admin_type === 2 && adminInfo.action_permissions.includes('2'))" -->
                <el-upload ref="upload" :accept="uploadObjImgBanner.accept" :show-file-list="false" :auto-upload="true"
                  :http-request="uploadFileBannerFun">
                  <template #default>
                    <el-button type="text">上传封面图</el-button>
                    <div style="color: #abacab;font-size:12px">建议尺寸8:3</div>
                  </template>
                </el-upload>
                <el-button style="margin-left:20px" type="text" @click="delImgBanner(projectDetailInfo,projectIndex)">删除</el-button>

                
              </el-col>
              <el-col :span="6">项目分类：{{ projectDetailInfo.category }}</el-col>
              <el-col :span="6">
                  已注册用户项目权限
                <el-switch 
                  v-model="projectDetailInfo.old_user_restrtction_status" 
                  :before-change="(()=>{return changeProjectInfoStatus(projectDetailInfo,projectIndex,'old_user_restrtction')})"
                  />
                  <!-- :before-change="(()=>{return handleOpt('ZXZ_TEAM_PROFILE_ALL')})" -->
              </el-col>
              <el-col :span="6">限制：领取上限-{{ projectDetailInfo.limit }}，领取下限-{{
                  projectDetailInfo.lower_limit
              }}</el-col>
              <el-col :span="6">轮播图排序：{{ projectDetailInfo.slide_show_sort }}</el-col>
            
              <el-col :span="6">状态：
                <span v-if="projectDetailInfo.status === 0">未上线</span>
                <span v-if="projectDetailInfo.status === 1">已上线</span>
                <span v-if="projectDetailInfo.status === 2">已下线</span>
              </el-col>
              
              <el-col :span="6">
                  新注册用户默认增加项目权限
                <el-switch 
                  v-model="projectDetailInfo.new_user_restrtction_status" 
                  :before-change="(()=>{return changeProjectInfoStatus(projectDetailInfo,projectIndex,'new_user_restrtction')})"
                  />
                  <!-- :before-change="(()=>{return handleOpt('ZXZ_TEAM_PROFILE_ALL')})" -->
              </el-col>
              <el-col :span="6">
                <div class="flex-start-wrap">
                  <div class="">
                    题目完成限制时间：{{  projectDetailInfo.countdown_answer}}秒
                  </div>
                   <div class="">
                    题目领取CD：{{  projectDetailInfo.cd}}秒
                  </div>
                  <template v-if="projectIndex > 0">
                      <div class="">
                        {{projectIndex == 1?'一':'二'}}审快捷输入：
                        <el-tooltip placement="bottom">
                          <template #content>
                            <div style="min-width: 200px; max-width: 400px">
                              <div style="font-size: 14px; padding: 5px" v-for="(item, i) in projectDetailInfo.audit_quick_template"
                                :key="i">
                                {{ i + 1 }}、{{ item }}
                              </div>
                            </div>
                          </template>
                          <el-button type="text">查看</el-button>
                        </el-tooltip>
                      </div>
                      <div class="">
                        开启权限：{{ projectDetailInfo.open_perm }}
                      </div>
                  </template>
                
                </div>
              </el-col>
              <el-col :span="6">
                <div>
                  <div>
                    {{projectIndex == 0 ? '废弃原因' : projectIndex == 1?'一审放弃原因':'二审放弃原因'}}：
                    <el-tooltip placement="bottom">
                      <template #content>
                        <div style="min-width: 200px; max-width: 400px">
                          <div style="font-size: 14px; padding: 5px" v-for="(item, i) in projectDetailInfo.give_up_reasons"
                            :key="i">
                            {{ i + 1 }}、{{ item }}
                          </div>
                        </div>
                      </template>
                      <el-button type="text">查看</el-button>
                    </el-tooltip>
                  </div>
                  <template  v-if="projectIndex > 0">
                    <div>
                      领取与放弃上限增加：{{projectDetailInfo.ctrl_increment_unit}}
                    </div>
                    <div>
                      关闭权限：{{projectDetailInfo.close_perm}}
                    </div>
                  </template>
                
                </div>
              </el-col>
               <el-col :span="6"  v-if="projectIndex > 0">
                <div class="">
                  领取与放弃上限减少：{{projectDetailInfo.ctrl_decrease_unit}}
                </div>
              </el-col>
              <el-col :span="6">
                <div  class="flex-start-wrap">
                  <div class="">
                    下线时间：{{dateFormat(projectDetailInfo.offline_date_time)}}
                  </div>
                  <div>
                    上线时间：{{dateFormat(projectDetailInfo.online_date_time) }}
                  </div> 
                  <div class=""  v-if="projectIndex > 0">
                    固定时间驳回：{{projectDetailInfo.rejection_time_period}}
                  </div>
                </div>
              </el-col>
              
              <el-col :span="6" >
                <div class="flex-start-wrap" style="padding-right:20px;width:100%">
                  <div class="flex-between-wrap ">
                    <div >
                      项目单价：<span v-if="!projectDetailInfo.showInput">{{projectDetailInfo.project_price || '暂无'}}</span>
                        <el-input v-else style="width:auto" type="number" v-model="projectDetailInfo.project_price" placeholder="请输入项目单价"></el-input>
                    </div>
                    <el-button  v-if="!projectDetailInfo.showInput" type="text" @click="projectDetailInfo.showInput = true">修改</el-button>
                    <template v-else>
                      <el-button  type="text" @click="changeProjectInfoPrice(projectDetailInfo,projectIndex,'project_price')">确认</el-button>
                      <el-button  type="text" @click="projectDetailInfo.showInput = false">取消</el-button>
                    </template>
                  </div>
                  <div class="flex-between-wrap">
                      <div class="flex-start-nowrap">
                        <div >项目描述：</div> {{projectDetailInfo.describe && projectDetailInfo.describe.substring(0,30)}}  
                      </div>
                      <el-button type="text" @click="projectPromptShow(projectDetailInfo,projectIndex)">修改</el-button>
                      
                  </div>
                </div>
              </el-col>

          </template>
          
          <!-- <el-col :span="6">一审快捷输入：{{ projectDetailInfo.slide_show_sort }}</el-col> -->
          <!-- <el-col :span="6">{{projectIndex == 1?'一':'二'}}审放弃原因：{{ projectDetailInfo.slide_show_sort }}</el-col> -->
         
        </el-row>
      </div>
    </div>
    <div class="layout-container">
      <div class="layout-container-form" style="flex-direction: column">
        <div class="layout-container-form-title">题库</div>
        <div class="layout-container-form-search">
          <el-row style="text-align: left">
            <el-col :span="24">
              <el-form label-width="90px" :inline="true">
                <el-form-item label="查询数据类型：" style="width:100%" label-width="120px" >
                    <el-select v-model="moneyOrGoods.index" placeholder="请选择数据类型" style="width: 392px"  @clear="clearStatus"
                    @change="changeMode">
                    <el-option v-for="item in moneyOrGoods.list" :key="item.value" :label="item.label" :value="item.value" />
                    </el-select>
                </el-form-item>
                <el-form-item label="题目名称：">
                  <el-input v-model="query.title" placeholder="请输入题目名称" style="width: 100%" clearable
                    @clear="getTableData(true)" @keyup.enter="getTableData(true)"></el-input>
                </el-form-item>
                <el-form-item label="用户昵称：">
                  <el-input v-model="query.nick_name" placeholder="请输入用户昵称" style="width: 100%" clearable
                    @clear="getTableData(true)" @keyup.enter="getTableData(true)"></el-input>
                </el-form-item>
                <el-form-item label="生效时间：">
                  <el-date-picker v-model="query.effective_time" type="datetimerange" prefix-icon="el-icon-date"
                    range-separator="→" format="YYYY-MM-DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss"
                    start-placeholder="开始日期" end-placeholder="结束日期" style="width: 100%" @change="changeEffectiveTime" />
                </el-form-item>
                <el-form-item label="题目ID：">
                  <el-input v-model="query.topic_id" placeholder="请输入题目ID" style="width: 100%" clearable
                    @clear="getTableData(true)" @keyup.enter="getTableData(true)"></el-input>
                </el-form-item>
                <el-form-item label="用户姓名：">
                  <el-input v-model="query.real_name" placeholder="请输入题目ID" style="width: 100%" clearable
                    @clear="getTableData(true)" @keyup.enter="getTableData(true)"></el-input>
                </el-form-item>
                <el-form-item label="截止时间：">
                  <el-date-picker v-model="query.end_date_time" type="datetimerange" prefix-icon="el-icon-date"
                    range-separator="→" format="YYYY-MM-DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss"
                    start-placeholder="开始日期" end-placeholder="结束日期" style="width: 100%" @change="changeEndDateTime" />
                </el-form-item>
                <el-form-item :label="moneyOrGoods.index == 0?'答主团队：':moneyOrGoods.index == 1?'一审团队：':'二审团队：'">
                  <el-input v-model="query.team_number" placeholder="请输入团队" style="width: 100%"
                    @clear="getTableData(true)" @keyup.enter="getTableData(true)" clearable></el-input>
                </el-form-item>
                <el-form-item label="用户ID：">
                  <el-input v-model="query.user_id" placeholder="请输入用户ID" style="width: 100%" clearable
                    @clear="getTableData(true)" @keyup.enter="getTableData(true)"></el-input>
                </el-form-item>
                <el-form-item label="完成时间：">
                  <el-date-picker v-model="query.finish_time" type="datetimerange" prefix-icon="el-icon-date"
                    range-separator="→" format="YYYY-MM-DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss"
                    start-placeholder="开始日期" end-placeholder="结束日期" style="width: 100%" @change="changeFinishTime" />
                </el-form-item>
                 <el-form-item label=""></el-form-item>
                <el-form-item label="状态：">
                  <el-select v-model="query.status" placeholder="请选择状态" style="width: 100%" clearable
                    @change="changeStatus">
                    <el-option v-for="item in statusOptions" :key="item.value" :label="item.label"
                      :value="item.value" />
                  </el-select>
                </el-form-item>
                <!-- <el-form-item label="团队编号：">
                  <el-input v-model="query.team_number" placeholder="请输入团队编号" style="width: 100%" clearable
                    @clear="getTableData(true)" @keyup.enter="getTableData(true)"></el-input>
                </el-form-item> -->
                <el-form-item>
                  <el-button class="search-btn" style="margin-left: 8px" @click="resetSearch">{{
                      $t("message.common.reset")
                  }}</el-button>
                  <el-button type="primary" class="search-btn" @click="getTableData(true)">{{
                      $t("message.common.search")
                  }}</el-button>
                </el-form-item>
              </el-form>
            </el-col>
          </el-row>
        </div>
        <div class="layout-container-opt" style="padding: 5px 15px !important;">
          <el-row>
            <el-col :span="24">
              <el-button
                v-if="adminInfo.admin_type < 2 || (adminInfo.admin_type === 2 && adminInfo.action_permissions.includes('2'))"
                type="primary" @click="handleBatchImport(1)">
                批量导入新题目
              </el-button>
              <el-button
                v-if="adminInfo.admin_type < 2 || (adminInfo.admin_type === 2 && adminInfo.action_permissions.includes('2'))"
                @click="handleBatchImport(2)"> 批量强制回归题库数据 </el-button>
              <el-button
                v-if="adminInfo.admin_type < 2 || (adminInfo.admin_type === 2 && adminInfo.action_permissions.includes('2'))"
                @click="handleBatchImport(3)"> 批量指派返修题目 </el-button>
              <el-button
                v-if="adminInfo.admin_type < 2 || (adminInfo.admin_type === 2 && adminInfo.action_permissions.includes('2'))"
                @click="handleBatchImport(4)"> 批量指派新题目 </el-button>
              <el-button
                v-if="adminInfo.admin_type < 2 || (adminInfo.admin_type === 2 && adminInfo.action_permissions.includes('2'))"
                @click="handleBatchImport(5)"> 批量作废题目 </el-button>
                <el-button
                v-if="adminInfo.admin_type < 2 || (adminInfo.admin_type === 2 && adminInfo.action_permissions.includes('2'))"
                @click="handleBatchImport(10)"> 批量修改任务状态 </el-button>
            </el-col>
          </el-row>
        </div>
        <div class="layout-container-opt" style="padding: 5px 15px !important;">
            <div style="padding:0 20px 0 18px">
                <el-checkbox v-model="checkAll" label="1" @change="changeAll">全选</el-checkbox>
            </div>
            <!-- <el-button
                v-if="adminInfo.admin_type < 2 || (adminInfo.admin_type === 2 && adminInfo.action_permissions.includes('3'))"
                :type='primary' :disabled="selectTopicData.length != 0"
                :loading="exportBatchLoading" @click="exportAllExcelFun">
                批量导出所有题目答案与表格
              </el-button> -->
              <el-button
                v-if="adminInfo.admin_type < 2 || (adminInfo.admin_type === 2 && adminInfo.action_permissions.includes('3'))"
                :type="selectTopicData.length > 0 ? 'primary' : ''" :disabled="selectTopicData.length === 0"
                :loading="exportBatchLoading" @click="exportExcelFun">
                批量导出题目答案与表格
              </el-button>
              <el-button v-if="adminInfo.admin_type < 2" :type="selectTopicData.length > 0 ? 'primary' : ''"
                :disabled="selectTopicData.length === 0" @click="batchClear(1)">
                批量清空当前题目上传的答案；释放空间
              </el-button>
              <el-button v-if="adminInfo.admin_type < 2" :type="selectIdsData.length > 0 ? 'primary' : ''"
                :disabled="selectIdsData.length === 0" @click="batchClear(2)">
                批量删除当前题目；释放空间
              </el-button>
        </div>
      </div>
      <div class="layout-container-table">
        <Table ref="table" v-model:page="page" v-loading="loading" :showSelection="true" :data="tableData"
          :showIndex="false" @getTableData="getTableData" @selection-change="handleSelectionChange">
          <el-table-column prop="sn" label="序号" width="50">
          </el-table-column>
          <el-table-column prop="topic_id" label="题目ID" />
          <el-table-column prop="title" label="题目名称" show-overflow-tooltip width="200" />
          <el-table-column prop="TopicNote" label="备注" align="center" width="80">
            <template #default="scope">
              <el-tooltip placement="bottom">
                <template #content>
                  <div style="max-width: 400px">
                    <div v-for="(item, i) in scope.row.TopicNote" :key="i">
                      备注{{ i + 1 }}：{{ item.content }};
                    </div>
                  </div>
                </template>
                <el-button type="text">查看</el-button>
              </el-tooltip>
            </template>
          </el-table-column>
          <el-table-column prop="status" label="答主题目状态" align="center">
            <template #default="scope">
                   <!--  0 未生效 1已完成 2 已领取 3指派中 4返修中 5 闲置中 6 已作废 -->
                  <span v-if="scope.row.status == 0">未生效</span>
                  <span v-if="scope.row.status == 1">
                    {{  scope.row.now < scope.row.reject_time_stemp ?'返修中':'已完成' }}</span>
                  <span v-if="scope.row.status == 2">已领取</span>
                  <span v-if="scope.row.status == 3">指派中</span>
                  <span v-if="scope.row.status == 4">返修中</span>
                  <span v-if="scope.row.status == 5">闲置中</span>
                  <span v-if="scope.row.status == 6">已作废</span>
                  <span v-if="scope.row.status == 7">已失效</span>
            </template>
          </el-table-column>
          <el-table-column prop="one_status" label="一审题目状态" align="center">
            <template #default="scope">
              <span v-if="scope.row.one_status == 0">未生效</span>
                  <span v-if="scope.row.one_status == 1">
                    {{
                      
                     (scope.row.one_status == 1 && scope.row.one_audit_status != 0) ? '审核通过' : '审核不通过' 

                    }}</span>
                  <span v-if="scope.row.one_status == 2">已领取</span>
                  <span v-if="scope.row.one_status == 3">指派中</span>
                  <span v-if="scope.row.one_status == 4">返修中</span>
                  <span v-if="scope.row.one_status == 5">闲置中</span>
                  <span v-if="scope.row.one_status == 6">已作废</span>
                  <span v-if="scope.row.one_status == 7">已失效</span>
            </template>
          </el-table-column>
          <el-table-column prop="two_status" label="二审题目状态"  align="center">
            <template #default="scope">
              <span v-if="scope.row.two_status == 0">未生效</span>
                  <span v-if="scope.row.two_status == 1">
                    {{
                     (scope.row.two_status == 1 && scope.row.two_audit_status == 2 ? '审核通过' : '审核不通过' )
                    }}</span>
                  <span v-if="scope.row.two_status == 2">已领取</span>
                  <span v-if="scope.row.two_status == 3">指派中</span>
                  <span v-if="scope.row.two_status == 4">返修中</span>
                  <span v-if="scope.row.two_status == 5">闲置中</span>
                  <span v-if="scope.row.two_status == 6">已作废</span>
                  <span v-if="scope.row.two_status == 7">已失效</span>
            </template>
          </el-table-column>
          <el-table-column prop="effective_time" label="题目生效时间" width="140" sortable>
            <template #default="scope">
              {{ dateFormat(scope.row.effective_time) }}
            </template>
          </el-table-column>
          <el-table-column prop="end_date_time" label="截止时间" width="140" sortable>
            <template #default="scope">
              {{ dateFormat(scope.row.end_date_time) }}
            </template>
          </el-table-column>
          <el-table-column prop="finish_time" label="完成时间" width="140" sortable>
            <template #default="scope">
              <span v-if="scope.row.status === 0"></span>
              <span v-if="scope.row.status === 1">{{ dateFormat(scope.row.finish_time) }}</span>
            </template>
          </el-table-column>
            <el-table-column v-if="moneyOrGoods.index == 0" prop="reject_time" label="固定驳回时间" width="140" sortable>
            <template #default="scope">
              {{ scope.row.reject_time }}
            </template>
          </el-table-column>
          <template v-if="moneyOrGoods.index == 0">
            <el-table-column prop="nick_name" label="领取人">
              <template #default="scope">
                <el-tooltip placement="bottom">
                  <template #content>
                    <div style="max-width: 400px">
                      <div>领取人ID：{{ scope.row.receiver_id }}</div>
                      <div>领取人昵称：{{ scope.row.nick_name }}</div>
                      <div>领取人姓名：{{ scope.row.real_name }}</div>
                      <div>领取人团队：{{ scope.row.team_number }}</div>
                      <div>领取人邮箱：{{ scope.row.email }}</div>
                      <div>领取人手机号：{{ scope.row.phone }}</div>
                    </div>
                  </template>
                  <el-button type="text">{{ scope.row.nick_name }}</el-button>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column prop="team_number" label="团队编号" width="80" />
          </template>
          <template v-if="moneyOrGoods.index == 1">
            <el-table-column prop="nick_name" label="一审">
              <template #default="scope">
                <el-tooltip placement="bottom">
                  <template #content>
                    <div style="max-width: 400px">
                      <div>领取人ID：{{ scope.row.receiver_id }}</div>
                      <div>领取人昵称：{{ scope.row.nick_name }}</div>
                      <div>领取人姓名：{{ scope.row.real_name }}</div>
                      <div>领取人团队：{{ scope.row.team_number }}</div>
                      <div>领取人邮箱：{{ scope.row.email }}</div>
                      <div>领取人手机号：{{ scope.row.phone }}</div>
                    </div>
                  </template>
                  <el-button type="text">{{ scope.row.nick_name }}</el-button>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column prop="team_number" label="一审团队" />
          </template>
          <template v-if="moneyOrGoods.index == 2">
            <el-table-column prop="nick_name" label="二审">
              <template #default="scope">
                <el-tooltip placement="bottom">
                  <template #content>
                    <div style="max-width: 400px">
                      <div>领取人ID：{{ scope.row.receiver_id }}</div>
                      <div>领取人昵称：{{ scope.row.nick_name }}</div>
                      <div>领取人姓名：{{ scope.row.real_name }}</div>
                      <div>领取人团队：{{ scope.row.team_number }}</div>
                      <div>领取人邮箱：{{ scope.row.email }}</div>
                      <div>领取人手机号：{{ scope.row.phone }}</div>
                    </div>
                  </template>
                  <el-button type="text">{{ scope.row.nick_name }}</el-button>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column prop="team_number" label="二审团队" />
          </template>




          <el-table-column :label="$t('message.common.handle')" width="240">
            <template #default="scope">
              <!--  0 未生效 1已完成 2 已领取 3指派中 4返修中 5 闲置中 6 已作废 -->
              <el-button
                v-if="adminInfo.admin_type < 2 || (adminInfo.admin_type === 2 && adminInfo.action_permissions.includes('1'))"
                type="text" @click="handleOpt(scope.row, 'detail')">
                {{ $t("message.common.detail") }}
              </el-button>
              <span
                v-if="adminInfo.admin_type < 2 || (adminInfo.admin_type === 2 && adminInfo.action_permissions.includes('3'))">
                <!-- 只有已完成状态可以导出 -->
                <span v-if="scope.row.status === 1">
                  <span class="split-line">|</span>
                  <el-button type="text" :loading="exportLoading" @click="handleOpt(scope.row, 'export')">
                    {{ $t("message.common.export") }}
                  </el-button>
                </span>
              </span>
              <span
                v-if="adminInfo.admin_type < 2 || (adminInfo.admin_type === 2 && adminInfo.action_permissions.includes('2'))">
                <!-- 只有作废才能回归题库 -->
                <span v-if="[1,2,3,4,5,6].indexOf(scope.row.status) !=-1">
                  <span class="split-line">|</span>
                  <el-button type="text" @click="handleOpt(scope.row, 'return_questions')">
                    {{ $t("message.common.return_questions") }}
                  </el-button>
                </span>
              </span>
              <span
                v-if="adminInfo.admin_type < 2 || (adminInfo.admin_type === 2 && adminInfo.action_permissions.includes('2'))">
                <!-- 只有已完成才能返修 -->
                <span v-if="scope.row.status === 1">
                  <span class="split-line">|</span>
                  <el-button type="text" @click="handleOpt(scope.row, 'repair')">
                    {{ $t("message.common.repair") }}
                  </el-button>
                </span>
              </span>
              <span
                v-if="adminInfo.admin_type < 2 || (adminInfo.admin_type === 2 && adminInfo.action_permissions.includes('2'))">
                <!-- 非作废条件下都可作废 -->
                <span v-if="[1,2,3,4,5].indexOf(scope.row.status) !=-1">
                  <span class="split-line">|</span>
                  <el-button type="text" @click="handleOpt(scope.row, 'invalid')">
                    {{ $t("message.common.invalid") }}
                  </el-button>
                </span>
              </span>
              <span v-if="adminInfo.admin_type === 0">
                <span class="split-line">|</span>
                <el-button type="text" @click="handleOpt(scope.row, 'del')">
                  {{ $t("message.common.del") }}
                </el-button>
              </span>
            </template>
          </el-table-column>
        </Table>
      </div>
      <!-- 批量导入弹出框 -->
      <!-- 上传文件弹出框组件 -->
      <BatchImportDialog v-if="uploadObj.visible" :visible="uploadObj.visible" :title="uploadObj.title"
        :uploadObj="uploadObj" @closeUploadDialog="closeUploadDialog" @refreshTable="refreshTable" />
      <!-- 项目提示设置 -->
      <ProjectPrompt v-if="dialogPromptData.visible" :visible="dialogPromptData.visible" :title="dialogPromptData.title"
        :dialogInfo="dialogInfo" @surePromptDialog="surePromptDialog" @closePromptDialog="closePromptDialog" />
    </div>
  </div>
</template>

<script setup lang="ts">
import { dateFormat, prefix, ossPrefix,ossPrefixNew } from "@/utils/index.ts";
import { defineComponent, ref, reactive, computed, watch,toRefs,onActivated, onDeactivated,onBeforeMount,onBeforeUnmount} from "vue";
import { Page } from "@/components/table/type";
import { ElMessage, ElMessageBox } from "element-plus";
import Table from "@/components/table/index.vue";
import BatchImportDialog from "@/components/uploadFile/batchImportDialog.vue";
import ProjectPrompt from "./components/projectPrompt.vue";
import {
  uploadProjectImg,
  uploadProjectImgBanner,
  changeProjectStatus,
  getTopicList,
  delTopic,
  batchClearUploadData,
  batchDelTopicData,
  changeTopicStatus,
  exportExcel,
  exportTopicAllExcel,getOne,changeProjectInfo, oldUserOpenOrClose,newUserOpenOrClose, delProjectImgBanner,delProjectImg,exportAnswer,exportAudit
} from "@/api/service/project.ts";
// import { getProjectList, delProject, changeProjectStatus } from "@/api/service/project.ts";
import { useRouter, useRoute } from "vue-router";
import { useStore } from "vuex";
const router = useRouter();
const route = useRoute();
const store = useStore();
let projectDetailInfoStore = {...store.state.user.projectDetailInfo}
// console.log('进入详情projectDetailInfoStore', projectDetailInfoStore)
let firstLoad = ref(true);
onActivated(()=>{
  if(!firstLoad.value){
    projectDetailInfoStore = {...store.state.user.projectDetailInfo};
    getDetail()
    console.log('每次进入详情projectDetailInfoStore', projectDetailInfoStore)
  }
  
})
onDeactivated(()=>{
  firstLoad.value = false
  // store.commit("user/projectDetailInfoChange", {project_id:projectDetailInfoStore.product_id});
})
// 面包屑导航
const goProjectMs = () => {
  router.push({
    path: '/backstagerpzzm/projectManagement'
  })
}

const projectDataAll = ref([])
const moneyOrGoods = reactive({
   index:0,
   cmd:'cashReviewRecords',
   export:'exportCashReviewRecords',
   list:[
    {
        label: '答主',
        value: 0,
        cmd:'cashReviewRecords',
        export:'exportCashReviewRecords'
    },
    {
        label: '一审',
        value: 1,
        cmd:'productReviewRecords',
        export:'exportProductReviewRecords'
    },
    {
        label: '二审',
        value: 2,
        cmd:'productReviewRecords',
        export:'exportProductReviewRecords'
    },
   ]
})
const projectDetailInfo = computed(()=>{
  return projectDataAll.value[moneyOrGoods.index]
});

watch(projectDetailInfo, (newValue, oldValue) => {
  console.log("projectDetailInfo发生了变化", newValue, oldValue);
})
watch( () => store.state.user.projectDetailInfo, (newValue, oldValue) => {
  console.log("sum发生了变化", newValue, oldValue);
})

const getDetail = ()=>{
  projectDataAll.value = []
  getOne({project_id: projectDetailInfo.value?.project_id || projectDetailInfoStore.project_id }).then((res:any) => {
    if(res.code == 200){
       let flag = false
      Object.keys(res.data).map((item:any,index:any) => {
        let row = res.data[item]
        if(row){
          row.visibility_status = row.visibility == 0?true:false;
          row.old_user_restrtction_status = row.old_user_restrtction == 0?false:true
          row.new_user_restrtction_status = row.new_user_restrtction == 0?false:true
          projectDataAll.value.push(row)
        }else{
          row = {}
          if(flag) return
          flag = true;
          if(index == 1){
            row.onlyBtn = true;
          }else if(index == 2){
            row.onlyBtn = true;
          }
           projectDataAll.value.push(row)
        }
      })
      let len = 0;
      if(projectDataAll.value[projectDataAll.value.length - 1].onlyBtn){
        len = projectDataAll.value.length - 1
      }else{
       len = projectDataAll.value.length 
      }
      moneyOrGoods.list = moneyOrGoods.list.slice(0, len)
      getTableData(true);
    }

  })
}
getDetail()

// 上传封面
const uploadList = reactive({
  name: "",
  url: '',
}); // 点击上传的暂存文件
// uploadList.url = prefix + projectDataAll.value[moneyOrGoods.index]cover;

const uploadObjImg = reactive({
  accept: ".png, .jpg, .jpeg",
});
const adminInfo = reactive(store.state.user.adminInfo);
const dialogInfo = reactive({
  id: '',
  content: '',
  cmd:'changeProjectInfo',
});
const uploadFileFun = (fileInfo: any,projectDetailInfo:any) => {
  // 1:查看权限, 2:上传权限, 3:下载权限
  // 上传权限的判断
  // if (
  //   adminInfo.admin_type === 2 &&
  //   !adminInfo.action_permissions.includes("2")
  // ) {
  //   ElMessage.error("温馨提示：对不起，您暂无上传权限。");
  //   return;
  // }
  // console.log(fileInfo);
  let file = fileInfo.file;
  const fileType = [".png", ".jpg", ".jpeg"];
  const type = file.name.substr(file.name.lastIndexOf(".")).toLowerCase();
  // 上传类型限制
  if (!fileType.includes(type)) {
    let type = fileType.join("，");
    ElMessage.error(`温馨提示：只支持${type}格式的文件`);
    return;
  }
  // 上传大小限制
  const sizeLimit = file.size / 1024 / 1024 <= 5;
  if (!sizeLimit) {
    ElMessage.error("文件最大不能超过5MB");
    return;
  }

  let formData = new FormData();
  formData.append("file", file);

  let data = {
    id: projectDetailInfo.Id, // 项目id
    data: formData,
  };
  uploadProjectImg(data).then((res: any) => {
    if (res.code) {
      getDetail()
    }
  });
};

const delImg = (project:any,index:any)=>{
  delProjectImg({id:project.Id}).then((res:any) => {
    project.cover = ''
    projectDataAll.value.splice(index,1,project)
  })
}
const delImgBanner = (project:any,index:any)=>{
  delProjectImgBanner({id:project.Id}).then((res:any) => {
    project.banner = ''
    projectDataAll.value.splice(index,1,project)
  })
}

const changeProjectInfoStatus = (project:any,index:any,type:string)=>{
  let data = {
    id:project.Id,
    [type]:(project[type +'_status']?0:1 )+''
  }
  if(type == 'visibility'){
    data[type] = (project[type +'_status']?1:0)+''
  }
  if(type == 'old_user_restrtction' || type == 'new_user_restrtction'){
      changeProjectInfoRest(data,project,index,type)
    return 
  }
  changeProjectInfoFunc(data,project,index,type)
}
const changeProjectInfoPrice = (project:any,index:any,type:string)=>{
  let data = {
    id:project.Id,
    project_price:project.project_price
  }
  changeProjectInfoFunc(data,project,index,type)
}
const changeProjectInfoRest = (data:any,project:any,index:any,type:string)=>{

  let par = {
    status:data[type] * 1,
    project_id:project.project_id+''
  }
 if(type == 'old_user_restrtction'){
    oldUserOpenOrCloseFunc(par,project,index,type)
     
  }else if(type == 'new_user_restrtction'){
    newUserOpenOrCloseFunc(par,project,index,type)
  }
}
const oldUserOpenOrCloseFunc = (data:any,project:any,index:any,type:string)=>{
  oldUserOpenOrClose(data).then((res:any) => {
    if(res.code == 200){
      ElMessage.success("操作成功！");
      if(type){
        project[type+'_status'] = !project[type+'_status']
      }
      projectDataAll.value.splice(index,1,project)
    }
  })
}

const newUserOpenOrCloseFunc = (data:any,project:any,index:any,type:string)=>{
  newUserOpenOrClose(data).then((res:any) => {
    if(res.code == 200){
      ElMessage.success("操作成功！");
      if(type){
        project[type+'_status'] = !project[type+'_status']
      }
      projectDataAll.value.splice(index,1,project)
    }
  })
}
const changeProjectInfoFunc = (data:any,project:any,index:any,type:string)=>{
  changeProjectInfo(data).then((res:any) => {
    if(res.code == 200){
      ElMessage.success("操作成功！");
      if(type){
        project[type+'_status'] = !project[type+'_status']
      }
      projectDataAll.value.splice(index,1,project)
    }
  })
}

// 轮播封面图
const uploadBannerList = reactive({
  name: "",
  url: '',
}); // 点击上传的暂存文件

const uploadObjImgBanner = reactive({
  accept: ".png, .jpg, .jpeg",
});
// const adminInfo = reactive(store.state.user.adminInfo);
// const dialogInfo = reactive({
//   id: projectDetailInfo.Id,
//   content: projectDetailInfo.hint,
// });
const uploadFileBannerFun = (fileInfo: any) => {
  // 1:查看权限, 2:上传权限, 3:下载权限
  // 上传权限的判断
  // if (
  //   adminInfo.admin_type === 2 &&
  //   !adminInfo.action_permissions.includes("2")
  // ) {
  //   ElMessage.error("温馨提示：对不起，您暂无上传权限。");
  //   return;
  // }
  // console.log(fileInfo);
  let file = fileInfo.file;
  const fileType = [".png", ".jpg", ".jpeg"];
  const type = file.name.substr(file.name.lastIndexOf(".")).toLowerCase();
  // 上传类型限制
  if (!fileType.includes(type)) {
    let type = fileType.join("，");
    ElMessage.error(`温馨提示：只支持${type}格式的文件`);
    return;
  }
  // 上传大小限制
  const sizeLimit = file.size / 1024 / 1024 <= 5;
  if (!sizeLimit) {
    ElMessage.error("文件最大不能超过5MB");
    return;
  }

  let formData = new FormData();
  formData.append("file", file);

  let data = {
    id: projectDetailInfo.value.Id, // 项目id
    data: formData,
  };
  uploadProjectImgBanner(data).then((res: any) => {
    if (res.code) {
      let data = res.data;
      getDetail()
    }
  });
};
// 操作
const handleOptStatus = (status: String) => {
  ElMessageBox.confirm(`是否确认当前操作?`, "", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "success",
  })
    .then(() => {
      // 项目下线或上线
      changeProjectStatusFun(status);
    })
    .catch(() => { });
};

// 修改项目状态
const changeProjectStatusFun = (status: any) => {
  // status => 0:未上线 1:已上线 2:已线下
  let data = {
    id: projectDetailInfo.value.Id,
    status: status === 1 ? 2 : 1,
  };
  changeProjectStatus(data).then((res: any) => {
    if (res.code === 200) {
      let msg = status === 1 ? "下线成功" : "上线成功";
      ElMessage.success(msg);
      let info = JSON.parse(JSON.stringify(projectDetailInfo.value));
      info.status = status === 1 ? 2 : 1;
      // store.commit("user/projectDetailInfoChange", info);
      projectDetailInfo.value.status = info.status;
    }
  });
};

// 项目提示配置
const dialogPromptData = reactive({
  title: "项目描述配置",
  visible: false,
});
const projectPromptShow = (project:any,index:any) => {
  dialogInfo.id = project.Id
  dialogInfo.content = project.describe
  dialogPromptData.visible = true;
};
const surePromptDialog = (d:any) => {
  let data = {
    id: d.id,
    describe: d.content
  }
  changeProjectInfo(data).then((res: any) => {
    if (res.code === 200) {
      ElMessage.success('保存成功！')
      closePromptDialog(true)
    }
  })
}
// 关闭配置弹出框
const closePromptDialog = (val: String) => {
  dialogPromptData.visible = false;
  if (val) {
    getDetail()
  }
};



// 存储搜索用的数据
const query = reactive({
  effective_time: [], // array[string] 题目生效时间
  end_date_time: [], // array[string] 截止时间
  finish_time: [], // array[string] 完成时间
  status: undefined, // integer 状态 0 未生效 1已完成 2 已领取 3指派中 4返修中 5 闲置中 6 已作废
  team_number: "", // string 团队编号
  title: "", // string 项目名称
  topic_id: undefined, // string
  nick_name:'',//用户昵称
  real_name:'',//真实姓名
  user_id:'',//用户Id
});
// 状态
// 0 未生效 1已完成 2 已领取 3指派中 4返修中 5 闲置中 6 已作废
// 答主处理中,一审处理中
const statusOptions = ref([ {
    label: "未生效",
    value: 0,
  },])

const statusOptions0 = ref([
 
  {
    label: "未生效",
    value: 0,
  },
  {
    label: "已完成",
    value: 1,
  },
  {
    label: "已领取",
    value: 2,
  },
  {
    label: "指派中",
    value: 3,
  },
  {
    label: "返修中",
    value: 4,
  },
  {
    label: "闲置中",
    value: 5,
  },
  {
    label: "已作废",
    value: 6,
  },
  {
    label: '已失效',
    value: 7
  }
]);
const statusOptions1 = ref([
  //  {
  //   label:'答主处理中',
  //   value:-2,
  // },
  {
    label: "未生效",
    value: 0,
  },
  {
    label: "审核通过",
    value: 1,
  },{
    label: "审核不通过",
    value: 8,
  },
  {
    label: "已领取",
    value: 2,
  },
  {
    label: "指派中",
    value: 3,
  },
  {
    label: "复审中",
    value: 4,
  },
  {
    label: "闲置中",
    value: 5,
  },
  {
    label: "已作废",
    value: 6,
  },
  {
    label: '已失效',
    value: 7
  }
]);
const statusOptions2 = ref([
  // {
  //   label:'答主处理中',
  //   value:-2,
  // },
  // {
  //   label:'一审处理中',
  //   value:-3,
  // },
  {
    label: "未生效",
    value: 0,
  },
  {
    label: "审核通过",
    value: 1,
  },{
    label: "审核不通过",
    value: 8,
  },
  {
    label: "已领取",
    value: 2,
  },
  {
    label: "指派中",
    value: 3,
  },
  {
    label: "复审中",
    value: 4,
  },
  {
    label: "闲置中",
    value: 5,
  },
  {
    label: "已作废",
    value: 6,
  },
  {
    label: '已失效',
    value: 7
  }
]);
 statusOptions.value = statusOptions0.value
// 生效时间change事件
const changeEffectiveTime = (val: any) => {
  if (!val) {
    query.effective_time = [];
  }
  getTableData(true);
};
// 生效时间change事件
const changeMode = (val: any) => {
  query.status = undefined
  if(val == 0){
    statusOptions.value = statusOptions0.value
  }else if(val == 1){
    statusOptions.value = statusOptions1.value
  }else if(val == 2){
    statusOptions.value = statusOptions2.value
  }
  getTableData(true);
};
// 截止时间change事件
const changeEndDateTime = (val: any) => {
  if (!val) {
    query.end_date_time = [];
  }
  getTableData(true);
};
// 完成时间change事件
const changeFinishTime = (val: any) => {
  if (!val) {
    query.finish_time = [];
  }
  getTableData(true);
};
// 状态change事件
const changeStatus = (val: any) => {
  console.log(val);
  if (val === "") {
    query.status = undefined;
  }
  getTableData(true);
};

// 分页参数, 供table使用
const page: Page = reactive({
  index: 1,
  size: 50,
  total: 0,
});
// 重置
const resetSearch = () => {
  query.effective_time = []; // array[string] 题目生效时间
  query.end_date_time = []; // array[string] 截止时间
  query.finish_time = []; // array[string] 完成时间
  query.status = undefined; // integer 状态 0 未生效 1已完成 2 已领取 3指派中 4返修中 5 闲置中 6 已作废 7 已失效
  query.team_number = ""; // string 团队编号
  query.title = ""; // string 项目名称
  query.topic_id = undefined; // string


  query.nick_name = ''; // string
  query.real_name = ''; // string
  query.user_id = ''; // string
  getTableData(true);
};
const getParams = ()=>{
    let obj = {
        page: page.index,
        page_size: page.size,
        effective_time: query.effective_time, // array[string] 题目生效时间
        end_date_time: query.end_date_time, // array[string] 截止时间
        finish_time: query.finish_time, // array[string] 完成时间
        status: query.status == undefined ? -1 : query.status, // integer 状态 0 未生效 1已完成 2 已领取 3指派中 4返修中 5 闲置中 6 已作废 7 已失效
        team_number: query.team_number, // string 团队编号
        title: query.title, // string 项目名称
        topic_id: query.topic_id, // string
        project_id: projectDataAll.value[moneyOrGoods.index].project_id,
        nick_name:query.nick_name,//用户昵称
        real_name:query.real_name,//真实姓名
        user_id:query.user_id,//用户Id
    }
    if(obj.status == -2){
      obj.status = -1
      obj.answer_status = '1'
    }else if(obj.status == -3){
       obj.status = -1
      obj.one_status = '1'
    }
    if(moneyOrGoods.index == 1){
      if(obj.status == 1){
        obj.audit_status = 1
      }
      if(obj.status == 8){
        obj.audit_status = 0
      }
    }

    if(moneyOrGoods.index == 2){
       if(obj.status == 1){
        obj.audit_status = 2
      }
      if(obj.status == 8){
        obj.status = 1
        obj.audit_status = 0
      }
    }
    return obj
}
const loading = ref(false);
const tableData = ref([]);
// 获取表格数据
// params <init> Boolean ，默认为false，用于判断是否需要初始化分页
const getTableData = (init: Boolean) => {
  loading.value = true;
  if (init) {
    page.index = 1;
  }
  let params = getParams()
  getTopicList(params)
    .then((res: any) => {
      let data = res.data.list;
      data.forEach((d: any) => {
        d.loading = false;
        d.now = dateFormat(new Date()) * 1
        d.reject_time = d.reject_time == '0001-01-01T00:00:00Z'?'':dateFormat(d.reject_time)
        d.reject_time_stemp = d.reject_time?dateFormat(d.reject_time) * 1:0
      });

      tableData.value = data;
      page.total = Number(res.data.count);
      if(checkAll.value){
          changeAll(true)
      }else{
        changeAll(false)
      }
    })
    .catch(() => {
      tableData.value = [];
      page.index = 1;
      page.total = 0;
    })
    .finally(() => {
      loading.value = false;
    });
};
// 批量导入
const uploadObj = reactive({
  fileType: [".xls", ".xlsx"],
  accept: ".xls, .xlsx", // 文件上传类型
  multiple: false, // 是否支持多选
  visible: false,
  title: "",
  url: "", // 批量导入用户接口地址
  downloadObj: {
    name: "",
    url: "",
  },
});
// 批量处理
const handleBatchImport = (type: Number) => {
  uploadObj.visible = true;
  uploadObj.type = ''
  switch (type) {
    case 1:
      uploadObj.title = "批量导入新题目";
      uploadObj.type = 'status'
      uploadObj.url = `/admin/topic/excel/imports/${projectDetailInfo.value.project_id}`;
      uploadObj.downloadObj.name = "题目上传表.xlsx"; // excel模板名称
      uploadObj.downloadObj.url = `${ossPrefixNew}题目上传表.xlsx`; // excel模板下载地址
      break;
    case 2:
      uploadObj.title = "批量强制回归题库数据";
      uploadObj.type = 'status'
      uploadObj.url = `/admin/topic/excel/regression_question_bank/${projectDetailInfo.value.project_id}`;
      uploadObj.downloadObj.name = "批量回归题库表.xlsx"; // excel模板名称
      uploadObj.downloadObj.url = `${ossPrefix}批量回归题库表.xlsx`; // excel模板下载地址
      break;
    case 3:
      uploadObj.title = "批量指派返修题目";
      uploadObj.type = 'status'
      uploadObj.url = `/admin/topic/excel/repair/${projectDetailInfo.value.project_id}`;
      uploadObj.downloadObj.name = "批量返修表.xlsx"; // excel模板名称
      uploadObj.downloadObj.url = `${ossPrefix}批量返修表.xlsx`; // excel模板下载地址
      break;
    case 4:
      uploadObj.title = "批量指派新题目";
      uploadObj.type = 'status'
      uploadObj.url = `/admin/topic/excel/assign_user/${projectDetailInfo.value.project_id}`;
      uploadObj.downloadObj.name = "批量指派表.xlsx"; // excel模板名称
      uploadObj.downloadObj.url = `${ossPrefix}批量指派表.xlsx`; // excel模板下载地址
      break;
    case 5:
      uploadObj.title = "批量作废题目";
      uploadObj.type = 'status'
      uploadObj.url = `/admin/topic/excel/invalid/${projectDetailInfo.value.project_id}`;
      uploadObj.downloadObj.name = "批量作废.xlsx"; // excel模板名称
      uploadObj.downloadObj.url = `${ossPrefix}批量作废.xlsx`; // excel模板下载地址
      break;
    case 10:
      uploadObj.title = "批量修改题目状态";
      uploadObj.type = 'status'
      uploadObj.url = `/admin/project/excel/imports1`;
      uploadObj.downloadObj.name = "批量修改题目状态.xlsx"; // excel模板名称
      uploadObj.downloadObj.url = `${ossPrefixNew}批量修改题目状态.xlsx`; // excel模板下载地址
      break;
    case 6:
      uploadObj.title = "上传配置表开启一审";
      uploadObj.type = 'status'
      uploadObj.url = `/admin/project/excel/imports1`;
      uploadObj.downloadObj.name = "审核项目开启表.xlsx"; // excel模板名称
      uploadObj.downloadObj.url = `${ossPrefixNew}审核项目开启表.xlsx`; // excel模板下载地址
      break;
    case 7:
      uploadObj.title = "上传表格修改一审配置 ";
      uploadObj.type = 'status'
      uploadObj.url = `/admin/project/excel/update1`;
      uploadObj.downloadObj.name = "审核项目修改表.xlsx"; // excel模板名称
      uploadObj.downloadObj.url = `${ossPrefixNew}审核项目修改表.xlsx`; // excel模板下载地址
      break;
    case 8:
      uploadObj.title = "上传配置表开启二审";
      uploadObj.type = 'status'
      uploadObj.url = `/admin/project/excel/imports2`;
      uploadObj.downloadObj.name = "审核项目开启表.xlsx"; // excel模板名称
      uploadObj.downloadObj.url = `${ossPrefixNew}审核项目开启表.xlsx`; // excel模板下载地址
      break;
    case 9:
      uploadObj.title = "上传表格修改二审配置 ";
      uploadObj.type = 'status'
      uploadObj.url = `/admin/project/excel/update2`;
      uploadObj.downloadObj.name = "审核项目修改表.xlsx"; // excel模板名称
      uploadObj.downloadObj.url = `${ossPrefixNew}审核项目修改表.xlsx`; // excel模板下载地址
      break;
    default:
      break;
  }

};
// 1:批量清空当前题目上传的答案；释放空间, 2:批量删除当前题目；释放空间
const batchClear = (type: Number) => {
  switch (type) {
    case 1:
      batchClearUploadDataFun();
      break;
    case 2:
      batchDelTopicDataFun();
      break;
    default:
      break;
  }
};

// 1:批量删除当前题目；释放空间,
const batchClearUploadDataFun = () => {
  let data = {
    ...getParams(),
    project_id: projectDetailInfo.value.project_id,
    topic_ids: selectTopicData.value,
  
  }
  if(checkAll.value){
    data.project_ids = [projectDetailInfo.value.project_id]
  }else{
    data.topic_ids = topic_ids
  }

  batchClearUploadData(data).then((res: any) => {
    if (res.code === 200) {
      checkAll.value = false;
      ElMessage.success('批量清空当前题目上传的答案释放空间成功!')
      getTableData(true)
    }
  })
};

const batchDelTopicDataFun = () => {
  let data = {
     ...getParams(),
    project_id: projectDetailInfo.value.project_id,
    ids: selectIdsData.value,
  }
  let topic_ids = selectProjectIdsData.value;
  delete data.page
  delete data.page_size
  if(checkAll.value){
    data.project_ids = [projectDetailInfo.value.project_id]
    delete data.ids;
  }else{
    data.topic_ids = topic_ids
  }
  batchDelTopicData(data).then((res: any) => {
    if (res.code === 200) {
      checkAll.value = false;
      ElMessage.success('批量删除当前题目释放空间成功！')
      getTableData(true)
    }
  })
};



// 关闭上传文件弹出框
const closeUploadDialog = (refresh:any) => {
  uploadObj.visible = false;
  if(uploadObj.type == 'status' && refresh){
    ElMessage.success('上传成功！')
    getDetail()
  }
};

// 导入题目答题配置
// const handleBatchUpdate = () => {
//   uploadObj.visible = true;
//   uploadObj.title = "导入题目答题配置";
//   uploadObj.url = "/admin/project/excel/update";
//   uploadObj.downloadObj.name = ""; // excel模板名称
//   uploadObj.downloadObj.url = ""; // excel模板下载地址
// };
// 导入接口成功！
const refreshTable = () => {
  getTableData(true);
};


const table = ref()
const checkAll = ref(false)
const changeAll = (e:any)=>{
    console.log(checkAll.value)
    if(e){
      if(selectTopicData.value.length == tableData.value.length) return
        table.value.$refs.systemTable.toggleAllSelection()
    }else{
      selectTopicData.value = [];
      selectIdsData.value = [];
      selectProjectIdsData.value = [];
      table.value.$refs.systemTable.clearSelection()
    }
}



// 勾选数据
const selectTopicData = ref([]); // 题目id
const selectIdsData = ref([]); // 系统id
const selectProjectIdsData = ref([]); // 项目id
const handleSelectionChange = (data: any) => {
  selectTopicData.value = [];
  selectIdsData.value = [];
  selectProjectIdsData.value = [];
  if(data.length){
    if(data.length != tableData.value.length){
      checkAll.value = false
    }
    data.forEach((item: Object) => {
      selectTopicData.value.push(item.topic_id);
      selectIdsData.value.push(item.Id);
      selectProjectIdsData.value.push(item.project_id);
    })
  }
};

// 导出题目答案与表格
const exportBatchLoading = ref(false);
const exportLoading = ref(false);
const exportExcelFun = () => {
  exportBatchLoading.value = true;
  exportExcelPost(selectIdsData.value, selectProjectIdsData.value);
}
const exportAllExcelFun = () => {
  exportBatchLoading.value = true;
  let params = {
    page: 1,
    effective_time: query.effective_time, // array[string] 题目生效时间
    end_date_time: query.end_date_time, // array[string] 截止时间
    finish_time: query.finish_time, // array[string] 完成时间
    status: query.status == undefined ? -1 : query.status, // integer 状态 0 未生效 1已完成 2 已领取 3指派中 4返修中 5 闲置中 6 已作废 7 已失效
    team_number: query.team_number, // string 团队编号
    title: query.title, // string 项目名称
    topic_id: query.topic_id, // string
    project_id: projectDetailInfo.value.project_id
  }
  exportAllExcelPost(params);
}
// 导出通用函数
const exportExcelPost = (topic_ids: any, project_ids: any) => {
  let data = {
    topic_ids: [], // array[interger]
    ...getParams()
    // project_ids: project_ids, // array[string]
  }
  if(checkAll.value){
    data.project_ids = [projectDetailInfo.value.project_id]
  }else{
    data.topic_ids = topic_ids
  }
  let test = null
  if(moneyOrGoods.index == 0){
    test = ()=>{return exportAnswer}
  }else{
    test = ()=>{return exportAudit}
  }
  test()(data).then((res: any) => {
    if (res.code === 200) {
      exportBatchLoading.value = false;
      exportLoading.value = false;
      ElMessage.success('导出成功');
      window.open(res.data);
    }
  })
}
const exportAllExcelPost = ( params: any) => {
  let data = params
  exportTopicAllExcel(data).then((res: any) => {
    if (res.code === 200) {
      exportBatchLoading.value = false;
      exportLoading.value = false;
      ElMessage.success('导出成功');
      window.open(res.data);
    }
  })
}
// 操作
const handleOpt = (row: any, type: String) => {
  // 题目详情 不需要二次弹框
  if (type === "detail") {
    store.commit("user/topicInfoChange", row);
    router.push({
      path: "/backstagerpzzm/projectEdit/projectEdit",
    });
    return;
  }
  ElMessageBox.confirm(`是否确认当前操作?`, "", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "success",
  })
    .then(() => {
      // 导出
      if (type === "export") {
        exportLoading.value = true
        let topic_ids = [row.Id]; // array[interger]
        let project_ids = [row.project_id]; // array[string]
        exportExcelPost(topic_ids, project_ids);
      }
      // 回归题库
      if (type === "return_questions") {
        changeTopicStatusFun(row, 5)
      }
      // 返修
      if (type === "repair") {
        changeTopicStatusFun(row, 4)
      }
      // 作废
      if (type === "invalid") {
        changeTopicStatusFun(row, 6)
      }
      if (type === "del") {
        deleteFun(row.Id);
      }
    })
    .catch(() => { });
};

// 回归题库,返修,作废
const changeTopicStatusFun = (row: any, status: Number) => {
  let data = {
    id: row.Id,
    status: status
  }
  changeTopicStatus(data).then((res: any) => {
    if (res.code === 200) {
      let msg = ''
      if (status === 5) {
        msg = '回归题库成功！'
      }
      if (status === 4) {
        msg = '返修成功！'
      }
      if (status === 6) {
        msg = '作废成功！'
      }
      ElMessage.success(msg);
      getTableData(true);
    }
  })
}

// 删除函数
const deleteFun = (id: any) => {
  let data = {
    id,
  };
  delTopic(data)
    .then((res: any) => {
      if (res.code == 200) {
        getTableData(false);
        ElMessage.success("删除成功！");
      } else {
        ElMessage.error("删除失败！");
      }
    })
    .catch(() => false);
};


</script>

<style lang="scss" scoped>
.layout-container {
  height: 1000px;
}

.layout-container-form {
  position: relative;
  padding: 0;

  .layout-container-form-title {
    border-bottom: 1px solid #eeeeee;
    padding: 20px;
    font-size: 18px;
    font-size: bold;
    text-align: left;
    margin-bottom: 20px;
  }
}

.layout-container-detail {
  text-align: left;
  background: #ffffff;
  padding: 20px;
  box-sizing: border-box;

  .detail-page-name {
    color: #9a9b9f;
    margin-bottom: 20px;

    span {
      cursor: pointer;
    }
  }

  .detail-page-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;

    .detail-page-title-top {
      display: flex;
      align-items: center;
    }

    .detail-title {
      font-size: 20px;
      font-weight: bold;
      margin-right: 10px;
      // max-width: 400px;

      overflow: hidden; //溢出内容隐藏
      text-overflow: ellipsis; //文本溢出部分用省略号表示
      display: -webkit-box; //特别显示模式
      -webkit-line-clamp: 2; //行数
      line-clamp: 2;
      -webkit-box-orient: vertical; //盒子中内容竖直排列
    }

    .detail-sort {
      font-size: 12px;
    }
  }

  .el-row-item {
    border-bottom: 1px solid #999;
    margin-bottom: 20px;
    :deep(.el-col) {
      margin-bottom: 25px;
      display: flex;
      align-items: center;
      font-size: 14px;
      color: #000000;
    }
  }
  .el-row-item:last-child{
    border-bottom: none;
  }
}

.layout-container-form-search {
  width: 100%;
  display: inline-block !important;
  justify-content: flex-start !important;
  padding: 0 20px;
  box-sizing: border-box;

  .search-btn {
    margin-right: 10px;
  }
}

.layout-container-opt {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  padding: 5px 20px;
}

.split-line {
  margin: 0 8px;
  color: #ccc;
}

.image-slot {
  width: 50px;
  height: 50px;
  background: #fafafa;
  color: #ccc;
  font-size: 12px;
  cursor: pointer;
}

.popperClass {
  background: #000000;
}
.flex-start-wrap{
  display: flex;
  flex-wrap: wrap;
  flex-direction: column;
}
.flex-between-wrap{
  display: flex;
  justify-content: space-between;
  flex-wrap: nowrap;
  align-items: center;
  >div:first-child{
    width: calc(100% - 30px);
  }

}
.flex-start-nowrap{
  display: flex;
  flex-wrap: wrap;
  flex-wrap: nowrap;
}
</style>
